package com.gitee.wsl.text.marker

/**
 * 给文本区间附加一个名称
 */
class NameMarker(textStart: Int, textEnd: Int, override val name: String?) : Marker(textStart, textEnd) {
    override fun offset(offset: Int): NameMarker {
        if (offset == 0) return this
        return NameMarker(textBegin + offset, textEnd + offset, name)
    }

    override fun toString(): String {
        val sb = StringBuilder()
        return appendPos(sb).append(':').append('@').append(name).toString()
    }

}

fun Marker.Companion.name(textStart: Int, textEnd: Int, name: String?): NameMarker {
    return NameMarker(textStart, textEnd, name)
}